package com.myservice;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * socket 结合Java多线程技术实现Javaweb服务器
 */
public class WebServer {
	/**
	 * 启动服务
	 * */
	public void serverStart(int port) {
		try {
			ServerSocket serverSocket = new ServerSocket(port);
			while (true) {
				Socket socket = serverSocket.accept();
				new Processer(socket).start();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public static void main(String[] args) {
		int port = 80;
		if (args.length == 1) {
			port = Integer.parseInt(args[0]);
		}
		System.out.println("启动了一个端口号为："+port+" 进程");
		new WebServer().serverStart(port);
	}

}
